package com.ruoyi.report.forms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.utils.uuid.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.report.forms.domain.ReportFormsTemplate;
import com.ruoyi.report.forms.service.IReportFormsTemplateService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2023-10-30
 */
@RestController
@RequestMapping("/template")
public class ReportFormsTemplateController extends BaseController
{
    @Autowired
    private IReportFormsTemplateService reportFormsTemplateService;

    /**
     * 查询【请填写功能名称】列表
     */
    /*@RequiresPermissions("report.forms:template:list")*/
    @GetMapping("/list")
    public TableDataInfo list(ReportFormsTemplate reportFormsTemplate)
    {
        startPage();
        List<ReportFormsTemplate> list = reportFormsTemplateService.selectReportFormsTemplateList(reportFormsTemplate);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    /*@RequiresPermissions("report.forms:template:export")*/
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReportFormsTemplate reportFormsTemplate)
    {
        List<ReportFormsTemplate> list = reportFormsTemplateService.selectReportFormsTemplateList(reportFormsTemplate);
        ExcelUtil<ReportFormsTemplate> util = new ExcelUtil<ReportFormsTemplate>(ReportFormsTemplate.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    /*@RequiresPermissions("report.forms:template:query")*/
    @GetMapping(value = "/{templateId}")
    public AjaxResult getInfo(@PathVariable("templateId") String templateId)
    {
        return success(reportFormsTemplateService.selectReportFormsTemplateByTemplateId(templateId));
    }

    /**
     * 新增【请填写功能名称】
     */
    /*@RequiresPermissions("report.forms:template:add")*/
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReportFormsTemplate reportFormsTemplate)
    {
        String id = UUID.fastUUID().toString();
        reportFormsTemplate.setTemplateId(id);
        reportFormsTemplate.setCompany(reportFormsTemplate.getLoginCompany());
        reportFormsTemplate.setCreateUser(reportFormsTemplate.getLoginUser());
        reportFormsTemplateService.insertReportFormsTemplate(reportFormsTemplate);
        return success(reportFormsTemplateService.selectReportFormsTemplateByTemplateId(id));
    }

    /**
     * 修改【请填写功能名称】
     */
    /*@RequiresPermissions("report.forms:template:edit")*/
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReportFormsTemplate reportFormsTemplate)
    {
        reportFormsTemplate.setCreateUser(reportFormsTemplate.getLoginUser());
        reportFormsTemplate.setUpdateUser(reportFormsTemplate.getLoginUser());
        return toAjax(reportFormsTemplateService.updateReportFormsTemplate(reportFormsTemplate));
    }

    /**
     * 删除【请填写功能名称】
     */
    /*@RequiresPermissions("report.forms:template:remove")*/
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{templateIds}")
    public AjaxResult remove(@PathVariable String[] templateIds)
    {
        return toAjax(reportFormsTemplateService.deleteReportFormsTemplateByTemplateIds(templateIds));
    }
}
